//
//  AppDelegate.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/6.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        
        window = UIWindow(frame: (UIScreen .mainScreen().bounds))
        
        //let mainVc = VIZMainTBC()
        
        self.registerNotification()
        window?.rootViewController = self.defaultViewController()
        
        window?.rootViewController = VIZWelcomeVC()

        
        
        
        window?.makeKeyAndVisible()
        
        return true
    }

    //注册通知
    private func registerNotification() {
        
        // object: 监听那个对象发出的通知  一般设置为 nil 表示监听任意对象发出的通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeViewController:", name: VIZchange, object: nil)
    }
    
    func changeViewController(n : NSNotification) {
        
        if n.object == nil {
            self.window?.rootViewController = VIZWelcomeVC()
        }else{
            self.window?.rootViewController = VIZMainTBC()
        }
        
    }
    
    
    
    //创建不同的控制器:监听的方法
    func defaultViewController()->UIViewController{
        
        return VIZUserViewAccountModel.shardInstance.isLogin ? VIZWelcomeVC() : VIZMainTBC()
        
    }
    
    
    
    
    
    
}

